import UtilsTo from './index';

describe('UtilsTo', () => {
    let utilsTo: any;

    beforeEach(() => {
        utilsTo = UtilsTo;
    });

    test('formatCurrency should format numbers correctly', () => {
        expect(utilsTo.formatCurrency(12345)).toEqual('12,345');
        expect(utilsTo.formatCurrency(12345.67)).toEqual('12,345.67');
    });

    test('generateUUID should generate a valid UUID', () => {
        const uuid = utilsTo.generateUUID();
        expect(uuid.length).toEqual(36);
    });

    test('generateUniqueTimestamp should generate a unique timestamp', () => {
        const timestamp1 = utilsTo.generateUniqueTimestamp();
        const timestamp2 = utilsTo.generateUniqueTimestamp();
        expect(timestamp1).not.toEqual(timestamp2);
    });

    test('getFirstChars should return the first few characters', () => {
        expect(utilsTo.getFirstChars('hello', {length: 3})).toEqual('hel');
    });

    test('getLastChars should return the last few characters', () => {
        expect(utilsTo.getLastChars('hello', {length: 3})).toEqual('llo');
    });

    test('cutString should cut the string with specified parameters', () => {
        expect(utilsTo.cutString('hello world', {count: 3, unit: '...'})).toEqual('hel...rld');
    });

    test('formatAmount should format amounts correctly', () => {
        expect(utilsTo.formatAmount(12345.67, {min: 2, max: 2})).toEqual('12,345.67');
    });

    test('amountConvert should convert amounts correctly', () => {
        expect(utilsTo.amountConvert(12345)).toEqual('12,345');
    });

    test('convertScientificNotation should convert scientific notation to normal number', () => {
        expect(utilsTo.convertScientificNotation(1e6)).toEqual('1000000');
    });

    test('generateRandomNumber should generate a random number with specified length', () => {
        const randomNumber = utilsTo.generateRandomNumber({count: 6});
        expect(randomNumber.length).toEqual(6);
    });

    test('shuffleArray should shuffle the array randomly', () => {
        const array = [1, 2, 3, 4, 5];
        const shuffledArray = utilsTo.shuffleArray(array);
        expect(shuffledArray.length).toEqual(array.length);
    });

    test('deepCopyJson should deep copy a JSON object', () => {
        const obj = {a: 1, b: 2};
        const copiedObj = utilsTo.deepCopyJson(obj);
        expect(copiedObj).toEqual(obj);
    });

    test('deepCopyArray should deep copy an array', () => {
        const array = [1, 2, 3];
        const copiedArray = utilsTo.deepCopyArray(array);
        expect(copiedArray).toEqual(array);
    });

    test('jsonToQueryString should convert JSON to query string', () => {
        const json = {a: 1, b: 2};
        const queryString = utilsTo.jsonToQueryString(json);
        expect(queryString).toEqual('a=1&b=2');
    });

    test('queryStringToJson should convert query string to JSON', () => {
        const queryString = 'https:www.baidu.com?a=1&b=2';
        const json = utilsTo.queryStringToJson(queryString);
        expect(json).toEqual({a: '1', b: '2'});
    });
});
